package com.qq.arr;

import com.sun.org.apache.xpath.internal.objects.XObject;

import java.util.Iterator;

//节点类
public class Node <T>{
    T obj;
    Node next;
    public Node(T obj) { this.obj = obj; }
}

//单链表
class Mylist<T>{
    Node head = null;//头指针


    //添加元素
    void add(T obj) {
        Node node = new Node(obj);
        node.next = head;
        head = node;
    }
    MyIterator getIterator(){
        MyIterator iterator = new MyIterator();
        iterator.cursor = head;
        return iterator;
    }
}
//迭代器
class MyIterator{
    Node cursor;//游标
    //返回是否还有节点
    boolean hasNext(){return cursor!=null;}
    //获取下一个节点对象
    Object next(){
        Node x = cursor;
        cursor = cursor.next;
        return x.obj;
    }
}